$(function () {
    var vCode
    $(".getCode").on("tap",function () {
        $(this).addClass("mui-disabled");
        $(this).html("正在发送");
        $.get("/user/vCode",function (result) {
            vCode=result.vCode
            var time=60;
            var timer=setInterval(function () {
                var html=""+time+"秒后再获取";
                $(".getCode").html(html)
                time--
                if(time<-1){
                    clearInterval(timer);
                    $(".getCode").removeClass("mui-disabled");
                    $(".getCode").html("获取验证码")
                }
            },1000)
        })
    })
    $(".registerBtn").on("tap",function () {
        var userName =$.trim($(".username").val());
        var passWord1 =$.trim($(".password1").val())
        var passWord2=$.trim($(".password2").val())
        var codeTxt=$.trim($(".codeTxt").val())
        if (!checkPhone(userName)) {
            mui.toast("手机不合法");
            return;
        }
        if(passWord1.length<6){
            mui.toast("密码不合法");
            return;
        }
        if(passWord1!=passWord2){
            mui.toast("密码输入不一致");
            return;
        }
        if(codeTxt!=vCode){
            mui.toast("验证码不正确");
            return;
        }
        if (!$(".isAgreeChk").is(":checked")){
            mui.toast("请阅读会员服务协议");
            return;
        }
        var Suju={
            username:userName,
            password:passWord1,
            mobile:codeTxt,
            vCode:codeTxt
        }
        $.post("/user/register",Suju,function (result) {
            if(result.success){
                location.href="../index.html";
            }else{
                mui.toast(result.message);
            }
        })
    })
    function checkPhone(phone) {
        var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
        //电话

        if (!phoneReg.test(phone)) {
            // 不满足
            return false;
        } else {
            return true;
        }

    }
})